]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell/window-tracker: Track ::window-created
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 16 Nov 2021 19:46:58 +0000 (20:46 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Thu, 16 Dec 2021 21:44:35 +0000 (22:44 +0100)
We currently track windows via MetaWorkspace's ::window-added and
::window-removed signals. Those aren't emitted for override-redirect
windows though, as those aren't actually located on any workspace
(see https://gitlab.gnome.org/GNOME/mutter/-/blob/gnome-41/src/core/window.c#L1322).

While that shouldn't be an issue as there's no good reason to look up
the ShellApp of an OR window, extensions can make modifications that
result in OR windows ending up in places that assume that every window
has an associated ShellApp.

We can either
 - accept that extensions break stuff (including badly)
 - carefully handle app-less windows everywhere
 - extend tracking to OR windows

Opt for the last option, as that's the most user-friendly and least
disruptive one.

It's also simpler to track ::window-created and ::unmanaged, as we
don't have to track workspaces or windows moving between workspaces.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4751

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2029>

src/shell-window-tracker.c

index cc03fb5f6ee3e1078540fd8c0acd601d01f13d3d..11e777d5d69124f6f6ff55133e3b8196d155aeb3 100644 (file)
@@ -557,9 +557,9 @@ track_window (ShellWindowTracker *self,
 }
 
 static void
-shell_window_tracker_on_window_added (MetaWorkspace   *workspace,
-                                      MetaWindow      *window,
-                                      gpointer         user_data)
+on_window_created (MetaDisplay *display,
+                   MetaWindow  *window,
+                   gpointer     user_data)
 {
   track_window (SHELL_WINDOW_TRACKER (user_data), window);
 }
@@ -588,14 +588,6 @@ disassociate_window (ShellWindowTracker   *self,
   g_object_unref (app);
 }
 
-static void
-shell_window_tracker_on_window_removed (MetaWorkspace   *workspace,
-                                     MetaWindow      *window,
-                                     gpointer         user_data)
-{
-  disassociate_window (SHELL_WINDOW_TRACKER (user_data), window);
-}
-
 static void
 load_initial_windows (ShellWindowTracker *tracker)
 {
@@ -622,51 +614,15 @@ load_initial_windows (ShellWindowTracker *tracker)
     }
 }
 
-static void
-shell_window_tracker_on_n_workspaces_changed (MetaWorkspaceManager *workspace_manager,
-                                              GParamSpec           *pspec,
-                                              gpointer              user_data)
-{
-  ShellWindowTracker *self = SHELL_WINDOW_TRACKER (user_data);
-  GList *workspaces;
-  GList *l;
-
-  workspaces = meta_workspace_manager_get_workspaces (workspace_manager);
-  for (l = workspaces; l; l = l->next)
-    {
-      MetaWorkspace *workspace = l->data;
-
-      /* This pair of disconnect/connect is idempotent if we were
-       * already connected, while ensuring we get connected for
-       * new workspaces.
-       */
-      g_signal_handlers_disconnect_by_func (workspace,
-                                            shell_window_tracker_on_window_added,
-                                            self);
-      g_signal_handlers_disconnect_by_func (workspace,
-                                            shell_window_tracker_on_window_removed,
-                                            self);
-
-      g_signal_connect (workspace, "window-added",
-                        G_CALLBACK (shell_window_tracker_on_window_added), self);
-      g_signal_connect (workspace, "window-removed",
-                        G_CALLBACK (shell_window_tracker_on_window_removed), self);
-    }
-}
-
 static void
 init_window_tracking (ShellWindowTracker *self)
 {
   MetaDisplay *display = shell_global_get_display (shell_global_get ());
-  MetaWorkspaceManager *workspace_manager =
-    meta_display_get_workspace_manager (display);
 
-  g_signal_connect (workspace_manager, "notify::n-workspaces",
-                    G_CALLBACK (shell_window_tracker_on_n_workspaces_changed), self);
   g_signal_connect (display, "notify::focus-window",
                     G_CALLBACK (on_focus_window_changed), self);
-
-  shell_window_tracker_on_n_workspaces_changed (workspace_manager, NULL, self);
+  g_signal_connect(display, "window-created",
+                   G_CALLBACK (on_window_created), self);
 }
 
 static void